<?php

    /**
    * Main class for working with cms settings.
    * @author NU SIT Bar
    * @version 1.0
    * @created 17.Jul.2012 17:39:44 h
    */

    class Settings extends MX_Controller 
    {

        private $data;

        function __construct()
        {
            parent::__construct();


            $this->load->model('settings_model');
            //$this->load->model('pages_model','posts_model');
            $this->load->library('translate', array('lang' => $this->session->userdata('my_language')));
            $this->load->config('pages');
        }

        function index() { show_404(); }

        function view_edit_thimbnail_size($params){

            $this->data['link'] = $params['link'];
            $this->data['page'] = ucfirst($_GET['post_type']);
            $this->data['title'] = "Edit ".$_GET['post_type'];
            $this->data['post_type'] = $_GET['post_type']; 
            $this->data['post_action'] = 'EDIT'; 
            $this->data['post'] = $this->settings_model->view_edit_thimbnail_size($_GET['post_ID']);
            echo $this->load->view('view_edit_thumbnail_size', $this->data, TRUE);

        }

        function view_add_thimbnail_size($params){

            $this->data['link'] = $params['link'];
            $this->data['page'] = ucfirst($_GET['post_type']);
            $this->data['title'] = "Add ".$_GET['post_type'];
            $this->data['post_type'] = $_GET['post_type']; 
            $this->data['post_action'] = 'NEW'; 
            echo $this->load->view('view_edit_thumbnail_size', $this->data, TRUE);

        }

        function view_all_thimbnail_size($params){

            $this->data['link'] = $params['link'];
            $this->data['page'] = ucfirst($_GET['post_type']);
            $this->data['title'] = "View All ".$_GET['post_type'];
            $this->data['post_type'] = $_GET['post_type']; 
            $this->data['all_posts'] = $this->settings_model->view_all_thumbnail_size(); 
            echo $this->load->view('view_all_thumbnail_size', $this->data, TRUE); 

        }

        function view_all_words($params){

            $this->load->helper('clean_html');
            
            $this->data['link'] = $params['link'];
            $this->data['page'] = ucfirst($_GET['post_type']);
            $this->data['title'] = "View All ".$_GET['post_type'];
            $this->data['post_type'] = $_GET['post_type']; 
            $this->data['all_words'] = $this->translate->trans_words_array($this->settings_model->view_all_words()); 
            echo $this->load->view('view_all_words', $this->data, TRUE); 

        }

        function view_edit_word($params){ 

            $this->data['link'] = $params['link'];
            $this->data['page'] = ucfirst($_GET['post_type']);
            $this->data['title'] = "Edit ".$_GET['post_type'];
            $this->data['post_type'] = $_GET['post_type']; 
            $this->data['post_action'] = 'EDIT'; 
            $this->data['word'] = $this->settings_model->view_edit_word($_GET['post_ID']);
            echo $this->load->view('edit_word', $this->data, TRUE);

        }
        
        function view_new_word($params){ 

            $this->data['link'] = $params['link'];
            $this->data['page'] = ucfirst($_GET['post_type']);
            $this->data['title'] = "Add ".$_GET['post_type'];
            $this->data['post_type'] = $_GET['post_type']; 
            $this->data['post_action'] = 'NEW'; 
            echo $this->load->view('edit_word', $this->data, TRUE);

        }

        function submit_post_thumbnails(){

            switch($_POST['post_action']){

                case 'NEW':     $this->settings_model->create_thumbnail_size(); $message = 'Successful new operation';
                    break;

                case 'EDIT':    $this->settings_model->update_thumbnail_size(); $message = 'Successful edit operation';
                    break;

            } 

            return TRUE.'-'.$message;

        }

        function submit_post_word(){

            switch($_POST['post_action']){

                case 'NEW':     $this->settings_model->create_word();   $message = 'Successful new operation';
                    break;

                case 'EDIT':    $this->settings_model->update_word();   $message = 'Successful edit operation';
                    break;

            }  

            return TRUE.'-'.$message;

        }

        function delete_thumbnail(){

            $this->settings_model->delete_thumbnail($_GET['post_ID']);

            return TRUE;

        }

        function delete_word($params){
            
            $this->settings_model->delete_word($params['ID']);
            return TRUE;

        }

        function change_lang(){

            /*$this->lang_ses->setLang($_POST['lang']);
            echo json_encode(true);  */

        }

}